package com.lb.jwitter.action;


import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.List; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTiet;
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTietService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblDKMHDotDKNhomtblDKMHDotDKHocVienChiTietSearchAction{
    private int pageSizeTblDKMHDotDKHocVienChiTiet; 
    public int getPageSizeTblDKMHDotDKHocVienChiTiet() {
        return pageSizeTblDKMHDotDKHocVienChiTiet;
 }

    public void setPageSizeTblDKMHDotDKHocVienChiTiet(int pageSizeTblDKMHDotDKHocVienChiTiet) {        this.pageSizeTblDKMHDotDKHocVienChiTiet = pageSizeTblDKMHDotDKHocVienChiTiet; }

    private int pageTblDKMHDotDKHocVienChiTiet; 
    public int getPageTblDKMHDotDKHocVienChiTiet() { return pageTblDKMHDotDKHocVienChiTiet; }

    public void setPageTblDKMHDotDKHocVienChiTiet(int pageTblDKMHDotDKHocVienChiTiet) { this.pageTblDKMHDotDKHocVienChiTiet = pageTblDKMHDotDKHocVienChiTiet; }

    private int pagesTblDKMHDotDKHocVienChiTiet; 
    public int getPagesTblDKMHDotDKHocVienChiTiet() { return pagesTblDKMHDotDKHocVienChiTiet; }

    public void setPagesTblDKMHDotDKHocVienChiTiet(int pagesTblDKMHDotDKHocVienChiTiet) { this.pagesTblDKMHDotDKHocVienChiTiet = pagesTblDKMHDotDKHocVienChiTiet; }

    private String dataStringTblDKMHDotDKHocVienChiTiet; 
    public String getDataStringTblDKMHDotDKHocVienChiTiet() { return dataStringTblDKMHDotDKHocVienChiTiet; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id ;
   }
    public void setId(int id) {
       this.id = id;
    }

    private int dotDKHocVienId; 
    public void setDotDKHocVienId(int dotDKHocVienId) {
       this.dotDKHocVienId = dotDKHocVienId;
  }

    public int getDotDKHocVienId() {
       return dotDKHocVienId;
  }

    private String ngayBatDau; 
    public void setNgayBatDau(String ngayBatDau) {
       this.ngayBatDau = ngayBatDau;
   }

    public String getNgayBatDau() {
       return ngayBatDau;
   }

    private String ngayKetThuc; 
    public void setNgayKetThuc(String ngayKetThuc) {
       this.ngayKetThuc = ngayKetThuc;
   }

    public String getNgayKetThuc() {
       return ngayKetThuc;
   }

    private String quyen; 
    public void setQuyen(String quyen) {
       this.quyen = quyen;
   }

    public String getQuyen() {
       return quyen;
   }

    private int nhomDKId; 
    public void setNhomDKId(int nhomDKId) {
       this.nhomDKId = nhomDKId;
  }

    public int getNhomDKId() {
       return nhomDKId;
  }

    private List<TblDKMHDotDKHocVienChiTiet> tblDKMHDotDKHocVienChiTiets; 
    public List<TblDKMHDotDKHocVienChiTiet>  getTblDKMHDotDKHocVienChiTiets() {
        return tblDKMHDotDKHocVienChiTiets; 
      } 

    private TblDKMHDotDKHocVienChiTietService tblDKMHDotDKHocVienChiTietService; 

	private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_DKMH_DotDK_HocVien_ChiTiet", "xem")){ 
        return "noprivilege"; 
    }        tblDKMHDotDKHocVienChiTietService = (TblDKMHDotDKHocVienChiTietService) context.getBean("tbl_DKMH_DotDK_HocVien_ChiTietClient"); 
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
    if(id != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("id");
        con.setValue1(id);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(dotDKHocVienId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("dotDKHocVienId.id");
        con.setValue1(new Long(dotDKHocVienId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(ngayBatDau != null && !ngayBatDau.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("ngayBatDau");
        con.setValue1(ngayBatDau);
        con.setOperator("eq");
        con.setType("date");
        cons.add(con);	
    } 
    if(ngayKetThuc != null && !ngayKetThuc.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("ngayKetThuc");
        con.setValue1(ngayKetThuc);
        con.setOperator("eq");
        con.setType("date");
        cons.add(con);	
    } 
    if(quyen != null && !quyen.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("quyen");
        con.setValue1(quyen);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(nhomDKId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("nhomDKId.id");
        con.setValue1(new Long(nhomDKId));
        con.setOperator("eq");
        cons.add(con);	
    } 
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSizeTblDKMHDotDKHocVienChiTiet == 0){ 
               pageSizeTblDKMHDotDKHocVienChiTiet = 20; 
           } 
            if(pageTblDKMHDotDKHocVienChiTiet == 0){ 
               pageTblDKMHDotDKHocVienChiTiet =1; 
           } 
           tblDKMHDotDKHocVienChiTiets = tblDKMHDotDKHocVienChiTietService.findtblDKMHDotDKHocVienChiTietByCondition(cons,pageSizeTblDKMHDotDKHocVienChiTiet,pageTblDKMHDotDKHocVienChiTiet); 
           pagesTblDKMHDotDKHocVienChiTiet = tblDKMHDotDKHocVienChiTietService.counttblDKMHDotDKHocVienChiTietByCondition(cons)/pageSizeTblDKMHDotDKHocVienChiTiet + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataStringTblDKMHDotDKHocVienChiTiet = ""; 
      dataStringTblDKMHDotDKHocVienChiTiet += "&id=" + id; 
      dataStringTblDKMHDotDKHocVienChiTiet += "&dotDKHocVienId=" + dotDKHocVienId; 
      dataStringTblDKMHDotDKHocVienChiTiet += "&ngayBatDau=" + ngayBatDau; 
      dataStringTblDKMHDotDKHocVienChiTiet += "&ngayKetThuc=" + ngayKetThuc; 
      dataStringTblDKMHDotDKHocVienChiTiet += "&quyen=" + quyen; 
      dataStringTblDKMHDotDKHocVienChiTiet += "&nhomDKId=" + nhomDKId; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_DKMH_DotDK_HocVien_ChiTiet Action"); 
         e.printStackTrace(); 
         msg.setPostMessage_b(false); 
         msg.setPostMessage_s(e.getMessage()); 
         return Action.ERROR; 
 } 
 } 
 } 
 
